<?php


namespace App\Traits;

trait Model
{

    public function getCreatedAtColumn()
    {
        return 'create_time';
    }

    public function getUpdatedAtColumn()
    {
        return 'update_time';
    }

    public function fromDateTime($value){
        return strtotime(parent::fromDateTime($value));
    }

    public function setLoginTimeAttribute($value){
        $this->attributes['login_time'] = strtotime($value);
    }

    public function getCasts()
    {
        if ($this->getIncrementing()) {
            return array_merge([$this->getKeyName() => $this->getKeyType()],
                [
                    'create_time' => 'datetime:Y-m-d H:i:s',
                    'update_time' => 'datetime:Y-m-d H:i:s',
                    'login_time' => 'datetime:Y-m-d H:i:s',
                ],$this->casts);
        }

        return $this->casts;
    }

}
